package com.allinpay.merchantweb.service.impl;

import java.nio.charset.StandardCharsets;

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author zzm
 * 
 * 增加tcp connect超时时间控制 
 * 减少出现 tcp SYNC_RECV状态的出现可能
 */
@Service
public class CustomizedRestTemplate extends RestTemplate{

	
	{
		HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
        httpRequestFactory.setConnectTimeout(1000);
        //httpRequestFactory.setReadTimeout(30000);
		this.setRequestFactory(httpRequestFactory);
		//修复请求报文 中文乱码问题
		this.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
	}
	
}
